/* This code is extracted from NewSyndrome kernel source code. It not really works 
but it's a good test to know if lib works or not */


#include <stdlib.h>
#include <gnutls/gnutls.h>


int main (void)
{
	gnutls_certificate_credentials_t xcred;
	gnutls_session_t session;
	int sd;
	const char *err;
	int ret;
	
	sd = 6;	/* fake socket() call */
	
	gnutls_global_init ();
	gnutls_certificate_allocate_credentials (&xcred);
	gnutls_certificate_set_x509_trust_file (xcred, "", GNUTLS_X509_FMT_PEM);

	gnutls_init (&session, GNUTLS_CLIENT);

	ret = gnutls_priority_set_direct (session, "PERFORMANCE", &err);
	if (ret < 0)
		return (-1);

	gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
	gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) ((long int) sd));
	ret = gnutls_handshake (session);

	if (ret < 0)
	{
		gnutls_deinit (session);
		gnutls_certificate_free_credentials (xcred);
		gnutls_global_deinit ();
		
		return (-1);
	}

	gnutls_bye (session, GNUTLS_SHUT_RDWR);
	gnutls_deinit (session);
	gnutls_certificate_free_credentials (xcred);
	gnutls_global_deinit ();	
	
	return (0);
}
